package com.e2e.haiti.infrastructure.surveyor;


import java.io.File;

import com.actionbarsherlock.app.SherlockActivity;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.widget.Toast;


public class Utils {
	
    private Context mContext;
    public static SqlHelper dbHelper = null;
    


    public Utils(Context context) {
        mContext = context;
    }

    public void openDatabase(){
    	    	
    	if (dbHelper == null) {
            dbHelper = new SqlHelper(mContext);
        }  
    	
    	if (dbHelper.dbSqlite == null) {
        	   dbHelper.createDatabase(dbHelper.dbSqlite);
           }
       dbHelper.openDataBase();    	
    }
    
    public void closeDatabase(){
    	try {

    		if (dbHelper.dbSqlite != null) {
                dbHelper.dbSqlite.close();
              }
    		
            if (dbHelper != null) {
                dbHelper.close();      
              }
    	
          } catch (Exception error) {
        	  error.printStackTrace();
          }
    }
    
    public void startNextActivity(int position, Class activityClass){
    	
        Intent myIntent = new Intent(mContext, activityClass);
         
        // Store structureIDvalue for new intent
        myIntent.putExtra("structureID", position);
        closeDatabase();
        mContext.startActivity(myIntent);
     }

    public Cursor getStructureCursor(int structureID){
    	openDatabase();
    	//Method cursor
    	Cursor tempCursor = null;
    	
     // Get cursor for current structure
    	String selection = SqlHelper.COLUMN_ID+"="+structureID;    	
    	 	
    	tempCursor = Utils.this.dbHelper.getCursor(selection);
    	tempCursor.moveToFirst();
    	closeDatabase();
    	return tempCursor;
    }
    

}